﻿@model MvcApplication1.Models.LoginModel
@{
    ViewBag.Title = "NetBooks";
}
@functions{
    public string GetAntiForgeryToken()
    {
        string cookieToken, formToken;
        AntiForgery.GetTokens(null, out cookieToken, out formToken);
        return cookieToken + ":" + formToken;                
    }
}

<div id="main-content">
@if (@User.Identity.IsAuthenticated)
{
    <p class="error" data-bind="text: error"></p>
    <input id="antiForgeryToken" type="hidden" value="@GetAntiForgeryToken()" />
    
    
    <section id="lists" data-bind="with: bookList">
        <article class="todoList">
            <ul data-bind="foreach: book">
                <li>
                    <input type="checkbox" data-bind="checked: isRead" />
                    <input class="todoItemInput" type="text" data-bind="value: title" />
                    <a href="#" data-bind="click: $parent.deleteBook">X</a>
                    <p class="error" data-bind="visible: errorMessage, text: errorMessage"></p>
                </li>
            </ul>
            <p class="error" data-bind="visible: errorMessage, text: errorMessage"></p>
        </article>
    </section>
}
else
{
    <div class="todoList" id="loginPanel">
        <section id="localLoginPanel">
            <h2>Log in</h2>
            @Html.Partial("_Login")
        </section>
        <p>First time here? <a id="showRegister">Sign up</a></p>
    </div>
    <div class="todoList" id="registerPanel">
        <h2>Sign up</h2>
        @Html.Partial("_Register")
        <p>Already signed up? <a id="showLogin">Log in</a></p>
    </div>
}
</div>

@if (@User.Identity.IsAuthenticated)
{
    @section scripts {
        @Scripts.Render("~/bundles/knockout")
        @Scripts.Render("~/bundles/jqueryval")
        @Scripts.Render("~/bundles/todo")
    }
}